import { objDeepCopy,getDateString } from "@/assets/js/common.js";
let Controller = {
	mounted() {
		
	},
	methods: {
		//查询单号
		checkNumbers() {
			this.$ajax({
				method: 'post',
				url:this.apiTest+'/supplier/whWarehouse/getWhwarehouseDetail',
				//url:'/api/supplier/whWarehouse/getWhwarehouseDetail',
				data:{
					number:this.Model.writePickingnum
				}
			}).then((res)=>{
				var data = res.data;
				if(data.status == 200){
					var result = data.result;
					if(result){
						if(result.status== 30){
							console.log(result)
							this.Model.whWarehouseId = result.id;
							this.Model.writeSkuDisabled = false;
							this.$nextTick(() => {
								this.$refs.SkuInput.$el.querySelector('input').focus()
							});
						}else{
							this.Model.writeSkuDisabled = true;
							this.tips(this,'warning','该单号不在出库状态内')
						}
					}else{
						this.Model.writeSkuDisabled = true;
						this.tips(this,'warning','该单号有误，请重新输入')
					}
					
					
				}else{
					
				}
					
			});
		},
		//请求扫码入库 
		skuEntryAjax(that,code){
			this.$ajax({
				method: 'post',
				url:this.apiTest+'/supplier/whWarehouseDetail/getByKeyWord',
				//url:'/api/supplier/whWarehouseDetail/getByKeyWord',
				data:{
					keyWord:code,
					whWarehouseId:this.Model.whWarehouseId
				}
			}).then((res)=>{
				var data = res.data;
				if(data.status == 200){
					var obj = {};
					var result = data.result;
					if(result){
						console.log(result)
						obj = objDeepCopy(result);
						that.Model.tableDataOut.push(obj)
					}
				}else{
		
				}
		
			});
		},
		
		//扫码入库
		checkSku(){
			var code = this.Model.writeSku;
			var tableDataOut = this.Model.tableDataOut;
			var codeIndexOf = this.valueInData(code,tableDataOut);
			if(codeIndexOf == -1){
				this.skuEntryAjax(this,code);
			}else{
				this.tips(this,'warning','条码已存在')
			}
		},
		//遍历 判断是否存在数组中
		valueInData(val,data){
			var indexof = -1;
			data.forEach(function(value,index,array){
				Object.keys(value).forEach(function(key){
					// console.log(key,value[key]);
					if(key == 'batchNo' && value[key] == val){
						indexof = 0;
						return;
					}
				});
			})
			return indexof;
		},
		//确认出库
		ToOutofstock() {
			var arr = [];
			var tableDataOut = this.Model.tableDataOut;
			for (let i = 0; i < tableDataOut.length; i++) {
				arr.push(tableDataOut[i].id);
			}
			if(tableDataOut.length == 0){
				this.tips(this,'warning','请选择数据');
				return;
			}
			//提交的数据 formInline
			var formInline = this.Model.formInline;
			formInline.ids = arr;
			formInline.whWarehouseId = this.Model.whWarehouseId;
			console.log(formInline)
			this.confirmNewAjax(this,formInline);
		},
		//确认出库 请求
		confirmNewAjax(that,params){
			this.$ajax({
				method: 'post',
				url:this.apiTest+'/supplier/whWarehouseDetail/outWarehouse',
				//url:'/api/supplier/whWarehouseDetail/outWarehouse',
				data:params
			}).then((res)=>{
				var data = res.data;
				if(data.status == 200){
					var result = data.result;
					if(result == 'OK'){
						that.tips(that,'success','操作成功');
						this.requestDetail(this,this.Model.orderNumber);
						this.$router.push({
							path:'receiveMaterial',
						})
					}else{
						that.tips(that,'warning',result)
					}
				}else{
					that.tips(that,'warning',data.msg)
				}
		
			});
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			console.log(val);
		},
		handleCurrentChange(val) {
			this.Model.pager.params.pageIndex = val;
		},
		handleSizeChange(val) {
			this.Model.pager.params.pageSize = val;
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = val;
		},
		toSearch(val) {
			console.log(val)
		},
		toClear(val) {
			this.Model.searchFromData = this.Model.defaultSearchFromData;
		},
		toExport(val) {
			console.log(val);
		},
		handleChange() {
			
		},	
		//出库
		OutOfstock() {
			
		},
		tips(that,type,message) {
			that.$message({
				message: message,
				type: type
			});
		},
	}
}
export default Controller;
